//
//  DetailPageControl.m
//  ybzj
//
//  Created by liyuan on 15/7/16.
//  Copyright (c) 2015年 liyuan. All rights reserved.
//

#import "DetailPageControl.h"

@implementation DetailPageControl

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void) setCurrentPage:(NSInteger)currentPage{
    [super setCurrentPage:currentPage];
    CGFloat width=[UIScreen mainScreen].bounds.size.width;
    for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) {
        UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
        subview.translatesAutoresizingMaskIntoConstraints=NO;
        NSLayoutConstraint *leftConstrain=[NSLayoutConstraint constraintWithItem:subview
                                                                      attribute:NSLayoutAttributeLeading
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:self
                                                                      attribute:NSLayoutAttributeLeading
                                                                     multiplier:1.0f
                                                                       constant:20*subviewIndex*width/640];
        NSLayoutConstraint *topConstrain=[NSLayoutConstraint constraintWithItem:subview
                                                                       attribute:NSLayoutAttributeTop
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:self
                                                                       attribute:NSLayoutAttributeTop
                                                                      multiplier:1.0f
                                                                        constant:0];
        NSLayoutConstraint *heightConstrain=[NSLayoutConstraint constraintWithItem:subview
                                                                       attribute:NSLayoutAttributeHeight
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:nil
                                                                       attribute:NSLayoutAttributeNotAnAttribute
                                                                      multiplier:1.0f
                                                                        constant:10*width/640];
        NSLayoutConstraint *equalConstrain=[NSLayoutConstraint constraintWithItem:subview
                                                                       attribute:NSLayoutAttributeHeight
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:subview
                                                                       attribute:NSLayoutAttributeWidth
                                                                      multiplier:1.0f
                                                                        constant:0];
        leftConstrain.active=YES;
        topConstrain.active=YES;
        heightConstrain.active=YES;
        equalConstrain.active=YES;
        
        if (subviewIndex == currentPage) {
            subview.backgroundColor=[UIColor greenColor];        }
        else {
            subview.layer.borderWidth=1.0f;
            subview.layer.borderColor=[[UIColor greenColor] CGColor];
        }
    }
    
}

-(void)changeCurrentPage:(NSInteger)currentPage{
    
     for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) {
         UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
         if (subviewIndex == currentPage) {
             subview.backgroundColor=[UIColor greenColor];        }
         else {
             subview.backgroundColor=[UIColor colorWithWhite:1.0 alpha:0];
             subview.layer.borderWidth=1.0f;
             subview.layer.borderColor=[[UIColor greenColor] CGColor];
         }

     }
  
}


@end
